package com.example.sunmiv1.adapter;


import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.activity.StringCodeOperationActivity;
import com.example.sunmiv1.entity.AllocationTubeListAlloDetailsBean;
import com.example.sunmiv1.utils.Tools;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AllocationTubeListAlloDetailsAdapter extends RecyclerView.Adapter<AllocationTubeListAlloDetailsAdapter.atldVHolder> {

    private List<AllocationTubeListAlloDetailsBean.DataBean> mList;
    private Context context;

    public AllocationTubeListAlloDetailsAdapter(List<AllocationTubeListAlloDetailsBean.DataBean> list) {
        super();
        mList = list;
    }

    @Override
    public atldVHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_allo_tube_list_allo_details, parent, false);
        context = parent.getContext();
        return new atldVHolder(view);
    }

    @Override
    public void onBindViewHolder(atldVHolder holder, int position) {
        holder.goodsName.setText(mList.get(position).getGoods_name());
        holder.goodsCode.setText(mList.get(position).getGoods_code());
        holder.goodsNumber.setText(mList.get(position).getGoods_number());
        Tools.hideViewInItem(mList.get(position).getCompany(),holder.goodsUnit);
        holder.infoSkuNum.setText(String.valueOf(mList.get(position).getSku_num()));
        holder.infoStockNum.setText(String.valueOf(mList.get(position).getStock_num()));
        holder.infoStockPrice.setText(String.valueOf(mList.get(position).getStock_price()));
        holder.infoSubtotal.setText(String.valueOf(mList.get(position).getSubtotal()));
        Tools.hideViewInItem(mList.get(position).getSku_name(), holder.infoSkuName);
        Tools.hideViewInItem(mList.get(position).getRemarks(), holder.infoRemark);
        if ("1".equals(mList.get(position).getSerial_number_state())) {
            holder.infoStockNum.setTextColor(ContextCompat.getColor(context, R.color.blue_3293FA));
        } else {
            holder.infoStockNum.setTextColor(ContextCompat.getColor(context, R.color.text_666));
        }
        holder.infoStockNum.setOnClickListener(v -> {
            if ("1".equals(mList.get(position).getSerial_number_state())) {
                Intent intent = new Intent(context, StringCodeOperationActivity.class);
                intent.putExtra("operation", 20);
                intent.putExtra("id", mList.get(position).getId());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    static class atldVHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.goods_name)
        TextView goodsName;
        @BindView(R.id.layout_goods_name)
        RelativeLayout layoutGoodsName;
        @BindView(R.id.goods_code)
        TextView goodsCode;
        @BindView(R.id.layout_goods_code)
        RelativeLayout layoutGoodsCode;
        @BindView(R.id.goods_number)
        TextView goodsNumber;
        @BindView(R.id.layout_goods_number)
        RelativeLayout layoutGoodsNumber;
        @BindView(R.id.goods_unit)
        TextView goodsUnit;
        @BindView(R.id.layout_unit)
        RelativeLayout layoutUnit;
        @BindView(R.id.info_sku_name)
        TextView infoSkuName;
        @BindView(R.id.layout_0)
        RelativeLayout layout0;
        @BindView(R.id.info_sku_num)
        TextView infoSkuNum;
        @BindView(R.id.layout_1)
        RelativeLayout layout1;
        @BindView(R.id.info_stock_num)
        TextView infoStockNum;
        @BindView(R.id.layout_2)
        RelativeLayout layout2;
        @BindView(R.id.info_stock_price)
        TextView infoStockPrice;
        @BindView(R.id.layout_3)
        RelativeLayout layout3;
        @BindView(R.id.info_subtotal)
        TextView infoSubtotal;
        @BindView(R.id.layout_4)
        RelativeLayout layout4;
        @BindView(R.id.info_remark)
        TextView infoRemark;

        public atldVHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
